//
//  FZEnglishLevelSelectView.m
//  EnglishTalk
//
//  Created by CyonLeuMBP on 2017/6/27.
//  Copyright © 2017年 Feizhu Tech. All rights reserved.
//

#import "FZEnglishLevelSelectView.h"

NSString *const kEnglishLevelCell = @"kEnglishLevelCell";

@interface FZEnglishLevelSelectView ()<UITableViewDataSource, UITableViewDelegate>

@property (strong, nonatomic) UITableView *tableView;



@end

@implementation FZEnglishLevelSelectView


- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        
//        FZStyleSheet *css = [FZStyleSheet currentStyleSheet];
        
//        self.items = @[@"总榜", @"入门", @"初级", @"中级", @"高级", @"专业" ];
        
        self.tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
        self.tableView.delegate = self;
        self.tableView.dataSource = self;
        self.tableView.rowHeight = 45;
        self.tableView.backgroundColor = [UIColor clearColor];
    
        [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:kEnglishLevelCell];
        
//        [self.tableView registerNib:[UINib nibWithNibName:kFZHomeMainCatagoryTableViewCell bundle:nil] forCellReuseIdentifier:kFZHomeMainCatagoryTableViewCell];
        
        [self addSubview:self.tableView];
        
        self.tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
        self.tableView.separatorInset = UIEdgeInsetsMake(0, 0, 0, 0);
        self.tableView.tableFooterView = [[UIView alloc] init];
        self.tableView.separatorColor = [UIColor whiteColor];
        
        [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.leading.trailing.bottom.top.equalTo(self);
            
        }];

    }
    
    return self;
}

- (NSString *)currentLevelName {
//    if (self.currentLevel >= 0 && self.currentLevel < [self.items count]) {
//        return self.items[self.currentLevel];
//    }
    return nil;
}

#pragma mark - UITableViewDataSource

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [self.items count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:kEnglishLevelCell forIndexPath:indexPath];
    cell.contentView.backgroundColor = [UIColor clearColor];
    cell.backgroundColor = [UIColor clearColor];
    
    SRSchoolClassListModel *item = self.items[indexPath.row];
    FZStyleSheet *css = [FZStyleSheet currentStyleSheet];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    cell.textLabel.font = css.fontOfH2;
    cell.textLabel.text = item.name;
    cell.textLabel.textAlignment = NSTextAlignmentCenter;
    cell.textLabel.textColor = [UIColor whiteColor];

//    if (self.currentModel && [self.currentModel.identifiter longLongValue] == [item.identifiter longLongValue]) {
//        cell.textLabel.textColor = css.color_1;
//    } else {
//        cell.textLabel.textColor = css.color_4;
//    }
    
    return cell;
}


#pragma mark - UITableViewDelegate


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    self.currentLevel = indexPath.row;
    SRSchoolClassListModel *item = self.items[indexPath.row];
    self.currentModel = item;
    
    if (self.didSelectBlock) {
        self.didSelectBlock(self.currentLevel, item);
    }
    
    [tableView reloadData];
}

- (void)reloadData {
    [self.tableView reloadData];
}


@end
